package com.bidevalution.controller.api;

import com.bidevalution.business.service.BeExpertAdviceSummaryService;
import com.bidevalution.dao.entity.BeExpertAdviceSummary;
import com.qtp.core.model.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 组长评审意见控制层
 *
 * @author 查慧英
 * @date 2019-11-20 17:45
 */
@RestController
@RequestMapping("/beAdviceSummary")
@Api(description = "组长评审意见")
public class BeExpertAdviceSummaryController extends BaseController {

    private Logger logger = Logger.getLogger(getClass());
    private static final String SECTION_ID = "sectionId";
    private static final String SEQ_ID = "seqId";
    private static final String CANDIDATE = "candidate";
    private static final String UNPASSED_INFO = "unpassedInfo";
    private static final String OBJECTION_INFO = "objectionInfo";
    private static final String EXPLAIN_INFO = "explainInfo";
    private static final String SIGN_INFO = "signInfo";
    @Autowired(required = false)
    private BeExpertAdviceSummaryService beExpertAdviceSummaryService;
    /**
     * 获取组长评审意见
     *  @param request
     * @param response
     */
    @ApiOperation(value = "获取组长评审意见", notes = "获取组长评审意见")
    @ApiImplicitParams({
            @ApiImplicitParam(name = SECTION_ID, value = "标段Id", required = true, paramType = "query", dataType = "String")
    })
    @PostMapping("/getBeExpertAdviceSummary")
    public Response<BeExpertAdviceSummary> getBeExpertAdviceSummary(HttpServletRequest request, HttpServletResponse response) {
        setHttpServletResponse(response);
        try {
            // 获取请求中的参数
            String sectionId = request.getParameter(SECTION_ID);
            return beExpertAdviceSummaryService.getBeExpertAdviceSummary(sectionId);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return null;
    }
    /**
     * 新增修改组长评审意见
     *  @param request
     * @param response
     */
    @ApiOperation(value = "新增修改组长评审意见", notes = "新增修改组长评审意见")
    @ApiImplicitParams({
            @ApiImplicitParam(name = SECTION_ID, value = "标段Id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = SEQ_ID, value = "主键", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = CANDIDATE, value = "推荐中标候选人", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = UNPASSED_INFO, value = "废标情况说明", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = OBJECTION_INFO, value = "有异议的意见和理由", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = EXPLAIN_INFO, value = "澄清说明补正事项纪要", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = SIGN_INFO, value = "签订合同前要处理的事宜", paramType = "query", dataType = "String")
    })
    @PostMapping("/addOrUpdate")
    public Response addOrUpdate(HttpServletRequest request, HttpServletResponse response) {
        setHttpServletResponse(response);
        try {
            // 获取请求中的参数
            BeExpertAdviceSummary item = new BeExpertAdviceSummary();
            item.setSectionId(request.getParameter(SECTION_ID));
            item.setCandidate(request.getParameter(CANDIDATE));
            item.setExplainInfo(request.getParameter(EXPLAIN_INFO));
            item.setSignInfo(request.getParameter(SIGN_INFO));
            item.setObjectionInfo(request.getParameter(OBJECTION_INFO));
            item.setUnpassedInfo(request.getParameter(UNPASSED_INFO));
            item.setSeqId(request.getParameter(SEQ_ID));
            return beExpertAdviceSummaryService.addOrUpdate(item);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return null;
    }
}
